package www.MoCh.com;

import java.util.ArrayList;
import java.util.Arrays;

public class Person implements Cloneable{
    private String name;
    private int age;
    Moneys m = new Moneys();

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person temp = (Person) super.clone();
        temp.m =(Moneys) this.m.clone();
        return temp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", m=" + m +
                '}';
    }

    public static void main(String[] args) throws CloneNotSupportedException{
        Person person1 = new Person("zhangsan", 32);
        Person person2 = (Person) person1.clone();
//        Person[] people = new Person[2];
//        people[0] = person1;
//        people[1] = person2;
//        System.out.println(Arrays.toString(people));
//
//        person2.name = "lisi";
//        person2.m.money = 1.2;
//        person2.age = 33;
//
//        System.out.println(Arrays.toString(people));

        ArrayList<Person> a = new ArrayList<>();
        a.add(person1);
        a.add(person2);
        System.out.println(a);
        person2.name = "lisi";
        person2.age = 53;
        person2.m.money = 13.3;
        System.out.println(a);


    }
}

class Moneys implements Cloneable{
    public double money = 3.2;

    @Override
    public String toString() {
        return "Moneys{" +
                "money=" + money +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
